import React, { Component } from 'react';
import axios from 'axios';
import {getQuery} from '../../utils/utils';
import qs from 'qs';
import NewsDetails from './newsDetails.jsx';
class mod extends Component {
        constructor(props) {
                super(props);
                console.log(props)
                console.log(this.props.location.search)
                this.state={
                        viewStatus:false,
                        id:getQuery(this.props.location.search,"id"),
                        record:{}
                }
                console.log(getQuery(this.props.location.search,"id"))
        }
        //初始化挂载
        componentDidMount() {
                this.getInfo(this.state.id)
        }
        getInfo = (id) => {
                let that=this
                axios.post("/api/?s=News.get",qs.stringify({id:id}))
                    .then(function (response) {
                            let result=response.data.data
                            that.setState(
                                {
                                        viewStatus:true,
                                        record:{
                                                "actionType":"mod",
                                                "id":result.id,
                                                "fatheridArr":result.fatheridArr.split(","),
                                                "fatherid":result.fatherid,
                                                "title":result.title,
                                                "orderNo":result.orderNo,
                                                "linkurl":result.linkurl,
                                                "imgurl":result.imgurl,
                                                "summary":result.summary,
                                                "content":result.content
                                        }
                                }
                            )
                    })
                    .catch(function (error) {
                            console.log(error);
                    })
        }
        render() {
                return(<div>
                    {this.state.viewStatus &&<NewsDetails  record={this.state.record}></NewsDetails>}
                    </div>
                )
        }
}
export default mod